package com.zerdoor.service.impl;

import com.zerdoor.dao.SettingDao;
import com.zerdoor.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by xiaoji on 2015/1/27.
 */
@Service
public class SettingServiceImpl implements SettingService {
    @Autowired
    private SettingDao settingDao;

    /**
     * 根据编号查询是否有对应数据
     *
     * @param configId
     * @return
     */
    @Override
    public Map<String, Object> getConfigById(int configId) {
        return settingDao.getConfigById(configId);
    }

    /**
     * 修改一个平台基本配置
     *
     * @param map 修改一个平台基本配置
     * @throws Exception
     */
    @Override
    public void updateConfig(Map<String, Object> map) throws Exception {
        Map<String, Object> config = settingDao.getConfigById(Integer.parseInt(map.get("configId").toString()));
        if(config == null){
            settingDao.addConfig(map);
        }else{
            settingDao.updateConfig(map);
        }

    }
}
